//
//  MYNewsParentingCell.m
//  MuYing
//
//  Created by tbb on 2019/8/2.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYNewsParentingCell.h"
#import "MYNewsParentingListVC.h"
#import <JXCategoryView/JXCategoryView.h>
@interface MYNewsParentingCell ()<JXCategoryListContainerViewDelegate,JXCategoryViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView * categoryView;
@property (nonatomic, strong) JXCategoryListContainerView * listContainerView;
@property (nonatomic, copy) NSArray * titles;
@end

@implementation MYNewsParentingCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.titles = @[kYQLS(@"景点"),kYQLS(@"酒店"),kYQLS(@"活动")];
        self.categoryView = [[JXCategoryTitleView alloc] init];
        self.categoryView.delegate = self;
        self.categoryView.titles = self.titles;
        self.categoryView.defaultSelectedIndex = 0;
            self.categoryView.cellSpacing = 32;
        self.categoryView.titleSelectedColor = kAPPThemeColor;//HexColor(0x79C4C7);
        self.categoryView.titleColor = HexColorA(0x000000, 0.1);
        self.categoryView.titleFont = kSystemMedium(12);
        self.categoryView.titleSelectedFont = kSystemMedium(12);
        self.categoryView.contentEdgeInsetLeft = 12;
        self.categoryView.backgroundColor = UIColor.whiteColor;
        self.categoryView.titleColorGradientEnabled = YES;
        self.categoryView.titleLabelZoomEnabled = YES;
        
        self.categoryView.averageCellSpacingEnabled = NO;
        
        JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
        lineView.indicatorColor = kAPPThemeColor;
        lineView.indicatorWidth = 24;
        lineView.indicatorHeight = 2.0;
        lineView.verticalMargin = 2;
        self.categoryView.indicators = @[lineView];
        
        self.categoryView.averageCellSpacingEnabled = NO;
        
        
        [self.contentView addSubview:self.categoryView];
        
        self.listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
        self.listContainerView.defaultSelectedIndex = 0;
        [self.contentView addSubview:self.listContainerView];
        
        self.categoryView.contentScrollView = self.listContainerView.scrollView;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.categoryView.frame = CGRectMake(0, 0, kYQPScreenWidth, 44);
    self.listContainerView.frame = CGRectMake(0, 44, kYQPScreenWidth, (2*kNEWS_PARENTING_LIST_H) + 74);
}

#pragma mark - JXCategoryViewDelegate

- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    [self.listContainerView didClickSelectedItemAtIndex:index];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
    [self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}
#pragma mark - JXCategoryViewDelegate end
#pragma mark - JXCategoryListContainerViewDelegate

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    MYNewsParentingListVC *listVC = [[MYNewsParentingListVC alloc] init];
    listVC.navVC = self.navVC;
    [self.YQViewController addChildViewController:listVC];
    return listVC;
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}

#pragma mark - JXCategoryListContainerViewDelegate end

@end
